//
//  TJCell.m
//  Food
//
//  Created by dlios on 15/7/18.
//  Copyright (c) 2015年 李志远. All rights reserved.
//

#import "TJCell.h"
#import "UIImageView+WebCache.h"
@implementation TJCell

- (void)dealloc
{
    [super dealloc];
    [_img release];
    [_name release];
    [_model release];
    [_myView release];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.myView = [[UIImageView alloc] init];
        self.myView.backgroundColor = [UIColor whiteColor];
        self.myView.layer.cornerRadius = 5;
        self.myView.layer.masksToBounds = YES;
        [self.contentView addSubview:self.myView];
        
        self.img = [[UIImageView alloc] init];
        self.img.layer.cornerRadius = 5;
        self.img.layer.masksToBounds = YES;
        [self.myView addSubview:self.img];
        
        self.name = [[UILabel alloc] init];
        self.name.font = [UIFont systemFontOfSize:15];
        self.name.textAlignment = NSTextAlignmentCenter;
        [self.myView addSubview:self.name];
        
    }
    return self;
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
    [super applyLayoutAttributes:layoutAttributes];
    self.myView.frame = CGRectMake(0, 0, layoutAttributes.frame.size.width , layoutAttributes.frame.size.height );
    self.img.frame = CGRectMake(3, 3, self.myView.frame.size.width - 6, 140);
    self.name.frame = CGRectMake(0, 145, self.myView.frame.size.width, 20);
}


- (void)setModel:(TJModel *)model
{
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    [self.img setImageWithURL:[NSURL URLWithString:model.picture_url] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    self.name.text = model.food_name;
}

@end
